<include file="public:header"/>
<include file="public:sidebar"/>
<script type="text/javascript" charset="utf-8" src="__STATIC__/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__STATIC__/ueditor/ueditor.all.min.js"> </script>
<script type="text/javascript" charset="utf-8" src="__STATIC__/ueditor/lang/zh-cn/zh-cn.js"></script>
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            设置抽奖
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
            <li class="active">抽奖</li>
        </ol>
    </section>
    <!-- Main content -->
    <section class="content">
        <div class="col-md-12">
            <div style="margin: 10px;">
                <button onclick="history.go(-1)" class="layui-btn layui-btn-sm layui-btn-radius layui-btn-danger">
                    <i class="layui-icon">&#xe65c;</i>返回
                </button>
            </div>
            <!-- Horizontal Form -->
            <div class="box box-info">
                <div class="box-header with-border">
                    <h3 class="box-title">添加/修改文章</h3>
                </div>
                <!-- /.box-header -->
                <!-- form start -->
                <form action="{:Url('article/lottery_insert')}" method="post" class="form-horizontal layui-form"
                      autocomplete="off">
                    <div class="box-body">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">
                                <span class="text-danger">*</span>所属文章
                            </label>
                            <div class="col-sm-4">
                                <input readonly type="text" class="form-control"
                                       placeholder="文章标题" value="<notempty name='info'>{$info.title}</notempty>">
                                <input type="hidden" name="aid"
                                       value="<notempty name='info'>{$info.id}</notempty>">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">
                                <span class="text-danger">*</span>奖项
                            </label>
                            <div class="col-sm-8">
                                <div class="col-sm-6 pl0">
                                    <input type="text" lay-verify="required" name="prize" class="form-control" placeholder="名称">
                                    <br/>
                                    <input type="text" lay-verify="money" name="money" class="form-control" placeholder="金额：0.3<= 金额 <=100">
                                    <br/>
                                    <input type="text" lay-verify="num" name="num" class="form-control" placeholder="数量">
                                </div>
                            </div>
                        </div>
                        <!--
                        <div class="form-group">
                            <label class="col-sm-2 control-label">
                                投放区域
                            </label>
                            <div class="col-sm-6 pl0" style="padding-left: 15px;">
                                <div class="col-sm-4 pl0">
                                    <select name="pro" lay-filter="pro">
                                        <option value="">--请选择--</option>
                                        <volist name="provinces" id="vo">
                                            <option value="{$vo.provinceid}">{$vo.province}</option>
                                        </volist>
                                    </select>
                                </div>
                                <div class="col-sm-4 pl0 city"></div>
                               <div class="col-sm-4 pl0 area"></div>
                                </div>
                        </div>
                        -->
                        <!--<div class="form-group">-->
                            <!--<label class="col-sm-2 control-label">-->
                                <!--结束时间-->
                            <!--</label>-->
                            <!--<div class="col-sm-4">-->
                                <!--<input type="text" class="form-control" name="end_time" readonly id="end_time">-->
                            <!--</div>-->
                        <!--</div>-->
                        <div class="form-group">
                            <label class="col-sm-2 control-label">
                                是否启用
                            </label>
                            <div class="col-sm-10">
                                <div class="radio">
                                    <label>
                                        <input type="radio" <empty name='info1'>checked<else/><eq name="info.status" value="1">checked</eq></empty> name="status" value="1">是
                                    </label>
                                    <label>
                                        <input type="radio" <notempty name='info1'><eq name="info.status" value="2">checked</eq></notempty> name="status" value="2">否
                                    </label>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">
                            </label>
                            <div class="col-sm-4">
                                <button type="submit" class="btn btn-info" lay-submit lay-filter="*">确定</button>
                                <!--<button type="reset" class="btn btn-default">取消</button>-->
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </section>
    <!-- /.content -->
</div>
<style>
.layui-form-radio {
    line-height: 30px;
    margin: 0 0 0 0;
    padding-right: 0;
}
.checkbox label, .radio label:first-child{
    padding-left: 0;
}
.pl0{
    padding-left: 0;
}
</style>
<script id="city" type="text/html">
    <select name="city" id="cities" lay-filter="city">
        {{#  layui.each(d.data, function(index, item){ }}
        <option value="{{item.cityid}}">{{item.city}}</option>
        {{#  }); }}
    </select>
</script>
<script id="area" type="text/html">
    <select name="area" id="areas" lay-filter="area">
        {{#  layui.each(d.data, function(index, item){ }}
        <option value="{{item.areaid}}">{{item.area}}</option>
        {{#  }); }}
    </select>
</script>
<script>
    layui.use(['form','layer','laydate','laytpl'],function () {
        var form = layui.form,
            layer = layui.layer,
            laydate= layui.laydate,
            laytpl = layui.laytpl;
        laydate.render({
            elem: '#end_time',
            type:'datetime'
        });

        form.on('select(pro)', function(data){
            $.get('{:Url("article/get_city")}',{pid: data.value},function (result) {
                var getTpl = city.innerHTML;
                laytpl(getTpl).render(result, function(html){
                    $('.city').html(html);
                    $('.area').html('');
                    form.render()
                });
            })
        });
        // form.on('select(city)', function(data){
        //     $.get('{:Url("article/get_areas")}',{cid: data.value},function (result) {
        //         var getTpl = area.innerHTML;
        //         laytpl(getTpl).render(result, function(html){
        //             $('.area').html(html);
        //             form.render()
        //         });
        //     })
        // });
        form.verify({
            money: function(value, item){
                if(!value){
                    return '请填写金额';
                }
                if(value < 0.3 || value > 100){
                    return '金额必须介于0.3到100元之间';
                }
            },
            num: function (value, item) {
                if(!value){
                    return '请填写数量';
                }
                if(!/^[0-9]*[1-9][0-9]*$/.test(value)){
                    return '数量必须是大于0的整数';
                }
            }
        });
        form.on('submit(*)', function(data){
            var index = layer.load();
            $.post(data.form.action,$('form').serialize(),function (result) {
                layer.close(index);
                if(result.code){
                    layer.msg(result.msg);
                    return false;
                }
                layer.alert(result.msg,{icon:6,end:function () {
                    history.go(-1);
                }});
            });
            return false;
        });
        $(document).on('click','.fa-close',function (e) {
            e.preventDefault();
            $('img.images').attr('src','');
            $('.show-image').hide();
        })
    });
</script>
<include file="public:footer"/>